<template>
  <div>
    <el-row>
      <el-col :span="12">
        <el-card>
          <template #header>
            <div>
              <span>重新提交申请</span>
            </div>
          </template>
          <el-form ref="form" :model="form2" label-width="120px">
            <el-form-item label="申请ID"> <span>{{ form2.applyId }}</span> </el-form-item>
            <el-form-item label="申请状态"> <span>{{ form2.status }}</span> </el-form-item>
            <el-form-item label="原请假天数"> <span>{{ form2.oldLeaveDays }}</span> </el-form-item>
            <el-form-item label="重新申请天数">
              <el-input-number v-model="form2.leaveDays" :min="1" :max="10" label="请假天数"></el-input-number>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="resubmit" v-loading.fullscreen.lock="loading">重新申请</el-button>
            </el-form-item>
          </el-form>
        </el-card>
      </el-col>
      <el-col :span="12">
        参数1：approveObject，当前选中待办的所有信息，供页面使用
        <pre style="max-height:200px;overflow-y: scroll;">{{ approveObject }}</pre>
        <hr />
        参数2：buttons，当前审批页面配置的按钮，可以使用也可以完全自定义处理
        <pre style="max-height:200px;overflow-y: scroll;">{{ buttons }}</pre>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { post } from '@/utils/ajax'

export default {
  name: "ResubmitPage",
  props: {
    approveObject: Object,
    buttons: Array,
  },
  data() {
    return {
      loading: false,
      form2: {},
    }
  },
  created() {
    this.init();
  },
  methods: {
    init() {
      const applyId = this.approveObject.businessKey;
      post("/samples/leave/selectById", { id: applyId }).then(response => {
        this.form2 = response.data;
        this.form2.oldLeaveDays = response.data.leaveDays;
      });
    },
    resubmit() {
      this.loading = true;
      const params = { ...this.form2, taskId: this.approveObject.taskId };
      post("/samples/leave/restartWfInstance", params).then(response => {
        this.loading = false;
        if (response.data === true) {
          this.msgSuccess("重新提交成功");
          // 触发关闭事件来关闭窗口
          // 参数1：固定值，close
          // 参数2: 可以自定义，查看/task/todo/index.vue中applyCloseHandler用途
          // 参数3：将提交后台的参数传递出去，目前还没有使用该值   
          this.$emit("close", "reApply", params);
        } else {
          this.msgError("重新提交失败");
        }
      });
    }
  }
}
</script>

<style lang="scss" scoped>
</style>